package com.hjw.oop;

/**
 *定义学生类
 * @author hjwStrart
 * @create 2022-01-07 14:49
 */
public class Student {
    private Integer age ;  //定义学生年龄
    private String name ;  //定义学生姓名
    private String no ;  //定义学生学号
    private String major;  //定义学生专业

    public Student() {
    }

    public Student(Integer age, String name, String no, String major) {
        this.age = age;
        this.name = name;
        this.no = no;
        this.major = major;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
        calculateAge();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }


    public void calculateAge(){
        if (age > 156 || age < 0){
            age = 20;
        }
    }
    @Override
    public String toString() {
        return  "姓名=" + name +
                ", 学号='" + no + '\'' +
                ", 专业='" + major + '\'' +
                ", 年龄='" + age + '\'';
    }
}
